﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using DragonsEyeAdventure.Utilities;

/*
 * Author: Nathaniel Edgar
 * Contributors:
 * File Version: v0.1
 * 
 * Copyright (C) 2013 Nathaniel Edgar
 * For full copyright information, please see the project README
 */

namespace DragonsEyeAdventure.Utilities
{
    /// <summary>
    /// Utility class for handling errors
    /// </summary>
    class ErrorHandler
    {
        #region Variables
        private const int errorBoxHeight = 5;
        private const string unknownErrorAlert = "There was an unknown error. Please restart the game.";
        #endregion

        #region Processing Methods
        /// <summary>
        /// Processes an unknown error
        /// </summary>
        public static void processError()
        {
            //Print error box
            printErrorBox();
            //Print alert
            Console.SetCursorPosition((Program.width - unknownErrorAlert.Length) / 2, 2);
            Console.Write(unknownErrorAlert);

            //Wait for the message to be read, then switch to the main menu so they can quit
            Thread.Sleep(3000);
            Program.currStatus = Program.EStatus.Menu;
        }
        #endregion

        #region Printing Methods
        /// <summary>
        /// Uses Printer.printBox to print an error box outline
        /// </summary>
        public static void printErrorBox()
        {
            //Prepare
            //Move any text out of the way
            Console.SetBufferSize(Program.width, Program.height + errorBoxHeight);
            Console.MoveBufferArea(0, 0, Program.width, Program.height, 0, errorBoxHeight);
            //Set the cursor position and color
            Console.SetCursorPosition(0, 0);
            Printer.setForeColor(ConsoleColor.Red);
            
            //Print the box
            Printer.printBox(0, 0, Program.width, errorBoxHeight);
        }
        #endregion
    }
}
